//
//  EnergyinfoView.m
//  Ginix
//
//  Created by 冯志强 on 2025/2/26.
//

#import "EnergyinfoView.h"
#import "EnergyCurrencyView.h"

@interface EnergyinfoView()
@property (nonatomic,strong) UIImageView * peopleView;
@property (nonatomic,strong) EnergyCurrencyView * currView1;
@property (nonatomic,strong) EnergyCurrencyView * currView2;
@property (nonatomic,strong) EnergyCurrencyView * currView3;
@property (nonatomic,strong) EnergyCurrencyView * currView4;
@property (nonatomic,strong) EnergyCurrencyView * currView5;
@property (nonatomic,strong) EnergyCurrencyView * currView6;
@property (nonatomic,strong) EnergyCurrencyView * currView7;
@property (nonatomic,strong) EnergyCurrencyView * currView8;

@property (nonatomic,strong) NSMutableArray * listArray;
@end

@implementation EnergyinfoView

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self setSubViewLayout];
    }
    return self;
}

-(void)setSubViewLayout{
    
    self.backgroundColor = UIColor.clearColor;
    
    [self addSubview:self.peopleView];
    [_peopleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(115 * FMScaleX, 180 * FMScaleX));
        make.centerX.equalTo(@0);
        make.top.mas_offset(55 * FMScaleX);
    }];
    
    [self addSubview:self.currView1];
    [_currView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.peopleView.mas_left).offset(-28 * FMScaleX);
        make.size.mas_offset(CGSizeMake(28 * FMScaleX, 28 * FMScaleX));
        make.top.equalTo(self.peopleView.mas_top).offset(46 * FMScaleX);
    }];
    [self addSubview:self.currView2];
    [_currView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.peopleView.mas_left).offset(-11 * FMScaleX);
        make.size.mas_offset(CGSizeMake(28 * FMScaleX, 28 * FMScaleX));
        make.top.equalTo(self.peopleView.mas_top).offset(10 * FMScaleX);
    }];
    [self addSubview:self.currView3];
    [_currView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.peopleView.mas_left).offset(-12 * FMScaleX);
        make.size.mas_offset(CGSizeMake(28 * FMScaleX, 28 * FMScaleX));
        make.bottom.equalTo(self.peopleView.mas_top).offset(10 * FMScaleX);
    }];
    
    [self addSubview:self.currView4];
    [_currView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_centerX).offset(-4.5 * FMScaleX);
        make.size.mas_offset(CGSizeMake(28 * FMScaleX, 28 * FMScaleX));
        make.bottom.equalTo(self.peopleView.mas_top).offset(-4 * FMScaleX);
    }];
    [self addSubview:self.currView5];
    [_currView5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_centerX).offset(4.5 * FMScaleX);
        make.size.mas_offset(CGSizeMake(28 * FMScaleX, 28 * FMScaleX));
        make.bottom.equalTo(self.peopleView.mas_top).offset(-4 * FMScaleX);
    }];
    [self addSubview:self.currView6];
    [_currView6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.peopleView.mas_right).offset(-15 * FMScaleX);
        make.size.mas_offset(CGSizeMake(28 * FMScaleX, 28 * FMScaleX));
        make.bottom.equalTo(self.peopleView.mas_top).offset(10 * FMScaleX);
    }];
    [self addSubview:self.currView7];
    [_currView7 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.peopleView.mas_right).offset(8 * FMScaleX);
        make.size.mas_offset(CGSizeMake(28 * FMScaleX, 28 * FMScaleX));
        make.top.equalTo(self.peopleView.mas_top).offset(10 * FMScaleX);
    }];
    [self addSubview:self.currView8];
    [_currView8 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.peopleView.mas_right).offset(28 * FMScaleX);
        make.size.mas_offset(CGSizeMake(28 * FMScaleX, 28 * FMScaleX));
        make.top.equalTo(self.peopleView.mas_top).offset(46 * FMScaleX);
    }];
    
    [self.listArray addObjectsFromArray:@[self.currView1,self.currView2,self.currView3,self.currView4,self.currView5,self.currView6,self.currView7,self.currView8]];
    
    
}

-(void)setInfoModel:(EnergyInfoModel *)infoModel{
    
    for (EnergyCurrencyView * view in self.listArray) {
        view.hidden = YES;
    }
    
    if (UserInfoModel.shareInstance.userModel.isBind != 1) {
        return;
    }
    
//    [self.peopleView sd_setImageWithURL:[NSURL URLWithString:infoModel.elvesDetail.imageUrl]];
    for (int i = 0; i < infoModel.notCollectedEnergy.count; i ++) {
        EnergyCurrencyView * view = self.listArray[i];
        view.hidden = NO;
        [view setID:infoModel.notCollectedEnergy[i]];
    }
    _peopleView.hidden = NO;
}

-(UIImageView *)peopleView{
    
    if(!_peopleView){
        _peopleView = [[UIImageView alloc]init];
        _peopleView.contentMode = UIViewContentModeScaleAspectFit;
        _peopleView.image = [UIImage  imageNamed:@"Energy_people_icon"];
        _peopleView.hidden = YES;
    }
    return _peopleView;
}
-(EnergyCurrencyView *)currView1{
    
    if (!_currView1) {
        _currView1 = [[EnergyCurrencyView alloc]init];
        _currView1.hidden = YES;
    }
    return _currView1;
}
-(EnergyCurrencyView *)currView2{
    
    if (!_currView2) {
        _currView2 = [[EnergyCurrencyView alloc]init];
        _currView2.hidden = YES;

    }
    return _currView2;
}
-(EnergyCurrencyView *)currView3{
    
    if (!_currView3) {
        _currView3 = [[EnergyCurrencyView alloc]init];
        _currView3.hidden = YES;

    }
    return _currView3;
}
-(EnergyCurrencyView *)currView4{
    
    if (!_currView4) {
        _currView4 = [[EnergyCurrencyView alloc]init];
        _currView4.hidden = YES;

    }
    return _currView4;
}
-(EnergyCurrencyView *)currView5{
    
    if (!_currView5) {
        _currView5 = [[EnergyCurrencyView alloc]init];
        _currView5.hidden = YES;

    }
    return _currView5;
}
-(EnergyCurrencyView *)currView6{
    
    if (!_currView6) {
        _currView6 = [[EnergyCurrencyView alloc]init];
        _currView6.hidden = YES;

    }
    return _currView6;
}
-(EnergyCurrencyView *)currView7{
    
    if (!_currView7) {
        _currView7 = [[EnergyCurrencyView alloc]init];
        _currView7.hidden = YES;

    }
    return _currView7;
}
-(EnergyCurrencyView *)currView8{
    
    if (!_currView8) {
        _currView8 = [[EnergyCurrencyView alloc]init];
        _currView8.hidden = YES;

    }
    return _currView8;
}

-(NSMutableArray *)listArray{
    
    if (!_listArray) {
        _listArray = [[NSMutableArray alloc]init];
    }
    return _listArray;
}
@end
